import { reqCategoryList, reqGetBannerList, reqFloorList } from '@/api'

const state = {
    // state中的初始值不要瞎写,服务器返回的是对象初始值就是对象,返回的是数组初始值就是数组
    categoryList: [],
    //轮播图的数据
    bannerList: [],
    floorList: []
}
const actions = {
    //通过API里面的函数调用,向服务器发请求获取数据
    async categoryList({ commit }) {
        let result = await reqCategoryList()
        if (result.code == 200) {
            commit("CATEGORYLIST", result.data)
        }
    },
    //获取banner数据
    async getBannerList({ commit }) {
        let result = await reqGetBannerList();
        if (result.code == 200) {
            commit('GETBANNERLIST', result.data)
        }
    },
    //获取floor数据
    async getFloorList({ commit }) {
        let result = await reqFloorList()
        if (result.code == 200) {
            commit('GETFLOORLIST', result.data)
        }
    }
}
const mutations = {
    CATEGORYLIST(state, categoryList) {
        categoryList = categoryList.slice(0, 16)
        state.categoryList = categoryList;
        // console.log(categoryList);
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList
    }
}
const getters = {}

export default {
    state, actions, mutations, getters
}